﻿namespace CodeBetter.Extensions.Tests
{
   using NUnit.Framework;
   using CodeBetter.Extensions;

   [TestFixture]
   public class ByteTests
   {
      [Test]
      public void ByteArrayToHex()
      {
         Assert.AreEqual("323717", new byte[] { 50, 55, 23 }.ToHex());
      }

      [Test]
      public void ToHex()
      {
         Assert.AreEqual("01", ((byte)1).ToHex());
      }

      [Test]
      public void SByte_ToHex()
      {
         Assert.AreEqual("1a", ((sbyte)26).ToHex());
         Assert.AreEqual("fe", ((sbyte)-2).ToHex());
      }

      [Test]
      public void Short_ToHex()
      {
         short w = 14;
         Assert.AreEqual("0e00", w.ToHex());
         w = 0x1f0e;
         Assert.AreEqual("0e", ((byte)w).ToHex()); // execpt??
         int i = 0x04030201;
         // 8bit layout / 16bit layout
         Assert.AreEqual("01020304", i.ToHex()); // little endian
         Assert.AreEqual("04030201", i.ToHex(HexOptions.EndianBig)); // big endian
         //byte? nb = null;
         //Assert.AreEqual(null, nb.ToHex());
         var enc = new BinHexEncoding();
         string test = enc.GetString(i.GetBytes()).ToString();
         byte[] tst = enc.GetBytes("0102030405060708090A0B0C0D0E0F");
      }
   }
}
